<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="string" uri="http://jakarta.apache.org/taglibs/string-1.1" %>
<%@ taglib uri="/WEB-INF/tlds/pagination.tld" prefix="pagination" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Dayve web</title>
<link href="/common/css/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/common/js/common.js"></script>
<script type='text/javascript' src="/common/dwr/engine.js"></script>
<script type='text/javascript' src="/common/dwr/util.js"></script>
<script type="text/javascript">
// 페이지 이동을 처리한다.
function goListPage(page) {
    var TheForm = document.frm;
    TheForm.currentPage.value = page;
    TheForm.nextTarget.value = 'noticeBoardList';
    TheForm.action = './noticeBoardList.do';
    TheForm.submit();
}

// 검색어로 리스트를 출력한다.
function jsSearchList() {
    var TheForm = document.frm;
    TheForm.title.value = TheForm.search_title.value;
    TheForm.writer_id.value = TheForm.search_writer.value;
    TheForm.writer_nick_name.value = TheForm.search_nickName.value;
    TheForm.content.value = TheForm.search_content.value;
    TheForm.nextTarget.value = 'noticeBoardList';
    TheForm.action = './noticeBoardList.do';
    TheForm.submit();
}

// 글쓰기 페이지로 이동 : 세션이 존재할 때만 가능
function jsWriteBoard() {
    var TheForm = document.frm;
    TheForm.nextTarget.value = 'noticeBoardWrite';
    TheForm.action = './noticeBoardWrite.do';
    TheForm.submit();
}

// 글수정 페이지로 이동 password 검사 : TheForm 에 Update Page 에 나올 내용을 담아 nextTarget 으로 넘겨준다
function jsUpdateBoard() {
    var TheForm = document.writeFrm;
    TheForm.nextTarget.value = 'noticeBoardUpdate';
    TheForm.action = './noticeBoardUpdate.do';
    TheForm.submit();
}

// 글 삭제 password 검사 리스트 페이지로 이동
function jsDeleteBoard() {
    if(confirm("<spring:message code="noticeBoardContent.confirm.del" />")){
        var TheForm = document.writeFrm;
//            var now = new Date();                                                  // 현재시간
//            var nowTime = now.getFullYear() + "년" + (now.getMonth()+1) + "월" + now.getDate() + "일" + now.getHours() + "시" + now.getMinutes() + "분";
//            TheForm.date.value = nowTime;
        TheForm.nextTarget.value = 'noticeBoardList';
        TheForm.action = './noticeBoardDelete.do';
        TheForm.submit();
    }

}

// 글보기 페이지로 이동
function jsContentView() {
    var TheForm = document.frm;
    TheForm.nextTarget.value = 'noticeBoardContent';
    TheForm.action = './noticeBoardContent.do';
    TheForm.submit();
}

// Community Board List 페이지로 이동한다.
function jsCommunityBoardList() {
    var TheForm = document.menuFrm;
    TheForm.nextTarget.value = "communityBoardList";	// page name
    TheForm.action = "./communityBoardList.do";
    TheForm.submit();
}

// Photo Board List 페이지로 이동한다.
function jsPhotoBoardList() {
    var TheForm = document.menuFrm;
    TheForm.nextTarget.value = "photoBoardList";	// page name
    TheForm.action = "./photoBoardList.do";
    TheForm.submit();
}

// Notice Board List 페이지로 이동한다.
function jsNoticeBoardList() {
    var TheForm = document.menuFrm;
    TheForm.nextTarget.value = "noticeBoardList";	// page name
    TheForm.action = "./noticeBoardList.do";
    TheForm.submit();
}

// Contact Us 페이지로 이동한다.
function jsContactUs() {
    var TheForm = document.menuFrm;
    TheForm.nextTarget.value = "contactus";	// page name
    TheForm.action = "./contactus.do";
    TheForm.submit();
}

// FAQ 페이지로 이동한다.
function jsFAQ() {
    var TheForm = document.menuFrm;
    TheForm.nextTarget.value = "faq";	// page name
    TheForm.action = "./faq.do";
    TheForm.submit();
}

// Comment 등록
function jsWriteComment(){
    var TheForm = document.commentFrm;
    if(trim(TheForm.commentContent.value) == ""){
        alert("<spring:message code="noticeBoardContent.alert" />");
        TheForm.commentContent.value = "";
        TheForm.commentContent.focus();
        return false;
    }else{
//            var now = new Date();                                                  // 현재시간
//            var nowTime = now.getFullYear() + "년" + (now.getMonth()+1) + "월" + now.getDate() + "일" + now.getHours() + "시" + now.getMinutes() + "분";
//            TheForm.date.value = nowTime;
        TheForm.nextTarget.value = "./noticeBoardContent.do?boardno=${board.notice_board_no}&page=${currentPage}&token=${board.notice_board_no}&token=${board.notice_board_no}&title&writer_id&writer_nick_name&content";
        TheForm.action = "./commentWrite.do";
        TheForm.submit();
    }
}

// Comment 삭제
function jsDeleteComment(cNo){
    if(confirm("<spring:message code="noticeBoardContent.confirm.del" />")){
        var TheForm = document.commentFrm;
//            var now = new Date();                                                  // 현재시간
//            var nowTime = now.getFullYear() + "년" + (now.getMonth()+1) + "월" + now.getDate() + "일" + now.getHours() + "시" + now.getMinutes() + "분";
//            TheForm.date.value = nowTime;
        TheForm.comment_no.value = cNo;
        TheForm.nextTarget.value = "./noticeBoardContent.do?boardno=${board.notice_board_no}&page=${currentPage}&token=${board.notice_board_no}&token=${board.notice_board_no}&title&writer_id&writer_nick_name&content";
        TheForm.action = "./commentDelete.do";
        TheForm.submit();
    }
}

// Comment 수정
function jsUpdateComment(cNo){
    if(confirm("<spring:message code="noticeBoardContent.confirm.upd" />")){
        var TheForm = document.commentFrm;
//            var now = new Date();                                                  // 현재시간
//            var nowTime = now.getFullYear() + "년" + (now.getMonth()+1) + "월" + now.getDate() + "일" + now.getHours() + "시" + now.getMinutes() + "분";
        var textAreaFlag = "commentUpdate" + cNo; // 사용한 TextArea 의 name 을 식별하기 위해 변수를 가져와서 합쳐줌
//            TheForm.date.value = nowTime;
        TheForm.comment_no.value = cNo;
        TheForm.content.value = document.getElementById(textAreaFlag).value; // 식별하기 위한 Flag 를 이용하여 content 값을 넣어줌
        if(trim(TheForm.content.value) == ""){
            alert('<spring:message code="noticeBoardContent.alert" />');
            TheForm.content.value = "";
            TheForm.content.focus();
            return false;
        }else{
            TheForm.nextTarget.value = "./noticeBoardContent.do?boardno=${board.notice_board_no}&page=${currentPage}&token=${board.notice_board_no}&title&writer_id&writer_nick_name&content";
            TheForm.action = "./commentUpdate.do";
            TheForm.submit();

        }

    }

}

function jsCommentEditShow(flag, cNo){          // cNo : undefined   , flag : kr.co.dayve.site.domain.Comment@a20f827 (뒤는 임시값?)
    var ct_none = "ct_none" + flag;
    var ct_show = "ct_show" + flag;
    var textAreaFlag = "commentUpdate" + cNo;
    document.getElementById(ct_none).style.display = "inline";      // 보여주기용 창은 닫고, 에딧용 창을 보여준다.
    document.getElementById(ct_show).style.display = "none";
    // 덤으로 <br> 을 줄 바꿈으로 바꿔 준다.
    var st = document.getElementById(textAreaFlag).value.replace(/<br>/ig,"\n");
    document.getElementById(textAreaFlag).value = st;
}

function jsCommentEditClose(flag){
    var ct_none = "ct_none" + flag;
    var ct_show = "ct_show" + flag;
    document.getElementById(ct_none).style.display = "none";
    document.getElementById(ct_show).style.display = "inline";
}

// Board List 출력
function jsBoardList() {
    var TheForm = document.writeFrm;
    TheForm.nextTarget.value = "noticeBoardList";	// page name
    TheForm.action = "./noticeBoardList.do";
    TheForm.submit();
}

function jsVote(){
    if(confirm("<spring:message code="noticeBoardContent.confirm.vot" />")){
        location.href = "noticeBoardVote.do?boardno=${board.notice_board_no}&page=${currentPage}&token=${board.notice_board_no}&title&writer_id&writer_nick_name&content";
    }
}

function jsReport(){
    if(confirm("<spring:message code="noticeBoardContent.confirm.rep" />")){
        location.href = "noticeBoardReport.do?boardno=${board.notice_board_no}&page=${currentPage}&title&writer_id&writer_nick_name&content";
    }
}

function jsBoardContent(boardno){
    var TheForm = document.frm;
    TheForm.boardno.value = boardno;
    TheForm.token.value = boardno;
    TheForm.nextTarget.value = 'noticeBoardContent';
    TheForm.action = './noticeBoardContent.do';
    TheForm.submit();
}


</script>
</head>

<body>
<div id="wrapper">
<!------------------------------ top 시작-------------------------------------->
<%@include file="header.jsp" %>
<!------------------------------ top 끝-------------------------------------->
<div class="sub_content">
<img src="/images/intro/sub_title01.gif" />
<table class="notice_tb">
    <tr>
        <td colspan="6" class="content_head">
            <c:out value="${board.title}"/>
        </td>
    </tr>
    <tr>
        <td width="7%" class="notice_tb_list">
            ${board.notice_board_no}
        </td>
        <td width="52%" class="notice_tb_title"><a href="#">${board.writer_nick_name} (${board.writer_id})</a></td>
        <%--<td width="17%" class="notice_tb_list"><a href="#">${board.modify_date}</a></td>--%>
        <td width="17%" class="notice_tb_list"><a href="#">${board.date_part_year}<spring:message code="noticeBoardContent.year" />${board.date_part_month}<spring:message code="noticeBoardContent.month" />${board.date_part_day}<spring:message code="noticeBoardContent.day" />${board.date_part_hour}:${board.date_part_minute}</a></td>
        <td width="8%" class="notice_tb_list"></td>
        <td width="8%" class="notice_tb_list"><spring:message code="noticeBoardContent.hitcount" /> ${board.hitcount}</td>
        <td width="8%" class="notice_tb_list"><!--<a href="javascript:jsReport()"><img src="/images/intro/btn_report.gif" /></a>--></td>
    </tr>
    <tr>
        <td colspan="6" class="notice_content"><p>
            ${board.content}
        </p></td>
    </tr>
    <c:set value="Y" var="addFile"/>
    <%-- 이전 업로드했던 이미지가 있을 경우.--%>
    <c:if test="${board.add_file_yn == addFile}">
        <tr>
            <td id="org_img_show"  colspan="6" class="write_tb02">
                    <%-- 해당 이미지의 원본 이름을 보여주고 클릭시 다운로드 하도록 한다.--%>
                <a href="/download.do?tFileName=${board.add_file_temp_name}&oFileName=${board.add_file_original_name}">${board.add_file_original_name}</a>&nbsp;&nbsp;${board.add_file_size}&nbsp;byte
            </td>
        </tr>
    </c:if>
</table>
<!---------------------------------------- 버튼 -------------------------------------->
<form name="writeFrm" method="POST">
    <input type="hidden" name="notice_board_no" value="${board.notice_board_no}">
    <input type="hidden" name="title" value="">
    <input type="hidden" name="writer_id" value="${board.writer_id}">
    <input type="hidden" name="writer_nick_name" value="">
    <input type="hidden" name="add_file_yn" value="N">
    <input type="hidden" name="date" value="">
    <input type="hidden" name="content" value="">
    <input type="hidden" name="modify_date" value="${board.modify_date}">
    <input type="hidden" name="nextTarget" value="">
    <input type="hidden" name="currentPage" value="${currentPage}">
    <div class="btn_right">
        <!-- HttpSession 이 존재하지 않을 경우 글쓰기 버튼 팝업 안됨-->
        <% if(null == s.getAttribute("userId")){  %>

        <%
        }else if(s.getAttribute("level").equals("1")){
        %>
        <!-- HttpSession 이 존재할 경우 수정 버튼 팝업 -->
        <a href="javascript:jsUpdateBoard()"><img src="/images/intro/btn_modify.gif" /></a>
        <a href="javascript:jsDeleteBoard()"><img src="/images/intro/btn_del.gif" /></a>

        <!-- HttpSession 이 존재할 경우 글쓰기 버튼 팝업 -->
        <a href="javascript:jsWriteBoard()"><img src="/images/intro/btn_write.gif" /></a>
        <% } %>
    </div>
    <div class="btn_left">
        <!--<a href="javascript:jsVote()"><img src="/images/intro/btn_like.gif" />--></a>
        <a href="javascript:jsNoticeBoardList()"><img src="/images/intro/btn_list.gif" /></a>
    </div>
</form>
<!---------------------------------------- 댓글 -------------------------------------->
<form name="commentFrm" method="POST">
    <input type="hidden" name="currentPage" value="${currentPage}">
    <input type="hidden" name="board_no" value="${board.notice_board_no}">
    <input type="hidden" name="writer_id" value="<%=s.getAttribute("userId")%>">
    <input type="hidden" name="writer_nick_name" value="<%=s.getAttribute("nickName")%>">
    <input type="hidden" name="flag" value="3"> <!-- 코멘트가 어느 게시판의 코멘트인지 식별하기 위한 플래그 -->
    <input type="hidden" name="date" value="">
    <input type="hidden" name="nextTarget" value="">
    <input type="hidden" name="content" value="">
    <input type="hidden" name="title" value="">
    <input type="hidden" name="comment_no" value="">
    <input type="hidden" name="commentDB" value="MYHISTORY_NOTICE_BOARD_COMMENT">
    <!-- comment List -->
    <c:set value="0" var="replyCount"/>
    <c:if test="${board.reply_count != replyCount}">   <!-- 게시물의 reply_count 가 0 이 아닐시 댓글 리스트 출력 -->

        <table class="notice_tb02">
            <c:forEach items="${commentList}" var="commentList" varStatus="commentStatus" begin="0" end="${commentCount}" step="1">
                <tr>
                    <td class="comment_idfirst">${commentList.writer_nick_name}</td>
                    <td class="comment_first" id="ct_show${commentList}" style="display: inline"> ${commentList.content}
                        <c:set value="${userId}" var="commentId"/>
                        <c:if test="${commentList.writer_id == commentId}">
                            <a href="javascript:jsCommentEditShow('${commentList}','${commentList.comment_no}')"><img src="/images/intro/btn_modify02.gif" /></a>
                            <a href="javascript:jsDeleteComment('${commentList.comment_no}')"><img src="/images/intro/btn_del02.gif" /></a>
                        </c:if>
                    </td>
                    <td class="comment_first" id="ct_none${commentList}" style="display: none"><textarea id="commentUpdate${commentList.comment_no}" style="height:150px; width: 800px;" >${commentList.content}</textarea>
                        <br/>
                        <a href="javascript:jsUpdateComment('${commentList.comment_no}')"><spring:message code="comment.update" /></a> | <a href="javascript:jsCommentEditClose('${commentList}')"><spring:message code="comment.cancel" /></a>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </c:if>
    <% if(null == s.getAttribute("userId")){  %>

    <%
    }else{
    %>
    <!-- HttpSession 이 존재할 경우 댓글 작성 팝업 -->
    <div class="space30">
        <textarea name="commentContent" cols="45" rows="3" class="comment_textarea"></textarea>
        <a href="javascript:jsWriteComment()"><img src="/images/intro/btn_register.gif" class="comment_btn" /></a>
    </div>
    <% } %>

</form>
<!---------------------------------------- 리스트 -------------------------------------->
<form name="frm" method="POST">
    <input type="hidden" name="notice_board_no" value="">
    <input type="hidden" name="title" value="">
    <input type="hidden" name="writer_id" value="">
    <input type="hidden" name="writer_nick_name" value="">
    <input type="hidden" name="content" value="">
    <input type="hidden" name="nextTarget" value="">
    <input type="hidden" name="currentPage" value="${currentPage}">

    <input type="hidden" name="boardno" value="">
    <input type="hidden" name="page" value="${currentPage}">
    <input type="hidden" name="token" value="">

    <table class="notice_tb">
        <tr>
            <td width="7%" class="notice_tb_headfirst"><spring:message code="noticeBoardList.no" /></td>
            <td width="58%" class="notice_tb_head"><spring:message code="noticeBoardList.title" /></td>
            <td width="10%" class="notice_tb_head"><spring:message code="noticeBoardList.writer_id" /></td>
            <td width="6%" class="notice_tb_head"> </td>
            <td width="6%" class="notice_tb_head"><spring:message code="noticeBoardList.hitcount" /></td>
            <td width="13%" class="notice_tb_headlast"><spring:message code="noticeBoardList.register_date" /></td>
        </tr>
        <c:set var="totalCount" value="${totalRow}"/>
        <c:forEach items="${boardList}" var="boardList" varStatus="serviceStatus" begin="0" end="20"
                   step="1">

            <tr>
                <td class="notice_tb_list">${boardList.notice_board_no}</td>
                <td class="notice_tb_title"><a href="javascript:jsBoardContent(${boardList.notice_board_no})">${boardList.title}
                    <c:if test="${boardList.reply_count > 0}">
                        <font size="1">[${boardList.reply_count}]</font>
                    </c:if> <!-- 댓글 존재시 -->
                </a></td>
                <td class="notice_tb_list">${boardList.writer_id}</td>
                <td class="notice_tb_list"> </td>
                <td class="notice_tb_list">${boardList.hitcount}</td>
                    <%--<td class="notice_tb_list">${boardList.modify_date}</td>--%>
                <td class="notice_tb_list">${boardList.date_part_year}년${boardList.date_part_month}월${boardList.date_part_day}일${boardList.date_part_hour}:${boardList.date_part_minute}</td>
            </tr>
        </c:forEach>
        <!--
        <tr>
            <td class="notice_tb_list">1</td>
            <td class="notice_tb_title"><a href="#">더욱 상세한 그래프를 제공하는 My Page 서비스가 오픈됩니다.</a></td>
            <td class="notice_tb_list"><a href="#">dayve</a></td>
            <td class="notice_tb_list">3</td>
            <td class="notice_tb_list">200</td>
            <td class="notice_tb_list">2012-04-03 16:13:11</td>
        </tr>
        -->
    </table>
    <!---------------------------------------- 버튼 -------------------------------------->
    <div class="btn_right">
        <!-- HttpSession 이 존재하지 않을 경우 글쓰기 버튼 팝업 안됨-->
        <% if(null == s.getAttribute("userId")){  %>

        <%
        }else if(s.getAttribute("level").equals("1")){
        %>
        <a href="javascript:jsWriteBoard()"><img src="/images/intro/btn_write.gif" /></a>
        <% } %>
    </div>
    <div class="btn_left">
        <a href="javascript:jsNoticeBoardList()"><img src="/images/intro/btn_list.gif" /></a>
    </div>
    <!------------------------------------ 검색 ----------------------------------------->
    <div class="content_center">
        <pagination:paging>
            <pagination:function>goListPage</pagination:function> <!-- 자바스크립트 함수 -->
            <pagination:currentPage>${currentPage}</pagination:currentPage> <!-- 현재페이지 -->
            <pagination:totalRows>${totalRow}</pagination:totalRows> <!-- 전체글수 -->
            <pagination:pageSize>${pageSize}</pagination:pageSize> <!-- 페이지당 조회건수 -->
        </pagination:paging>
        <!--
        <img src="/images/intro/btn_first.gif" class="tb_btn" />
        <img src="/images/intro/btn_prev.gif" class="tb_btn" />
        1 2 3 4 5
        <img src="/images/intro/btn_next.gif" class="tb_btn" />
        <img src="/images/intro/btn_last.gif" class="tb_btn" />
        -->
    </div>
    <!-------------------------------------- 검색 끝 -------------------------------------->
    <table class="search_tb">
        <tr>
            <td >&nbsp;</td>
            <td width="16%" class="search_text"><spring:message code="noticeBoardList.searchTitle" /></td>
            <td width="16%" class="search_text"><spring:message code="noticeBoardList.searchWriter" /></td>
            <td width="16%" class="search_text"><spring:message code="noticeBoardList.searchNickname" /></td>
            <td width="16%" class="search_text"><spring:message code="noticeBoardList.searchContent" /></td>
            <td width="22%" class="search_text">&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="text" name="search_title" class="notice_input" value="${param.search_title}"/></td>
            <td><input type="text" name="search_writer" class="notice_input" value="${param.search_writer}"/></td>
            <td><input type="text" name="search_nickName" class="notice_input" value="${param.search_nickName}"/></td>
            <td><input type="text" name="search_content" class="notice_input" value="${param.search_content}"/></td>
            <td><a href="javascript:jsSearchList()"><img src="/images/intro/btn_search.gif"  /></a></td>
        </tr>
    </table>
</form>
</div>
<!------------------------------ 하위메뉴 시작-------------------------------------->
<%@include file="footer.jsp" %>
<!------------------------------ 하위메뉴 끝-------------------------------------->
</div>
</body>
</html>
